module.exports = {
  apps: [
    {
      name: 'backend',
      script: './backend/dist/main.js',
      cwd: '/Users/zyu/leo/ignite-fun',
      instances: 1,
      exec_mode: 'fork',
      env: {
        NODE_ENV: 'production',
        PORT: 7172,
        DATABASE_URL: process.env.DATABASE_URL || 'postgresql://ignite:password@localhost:5432/ignite_db',
        HELIUS_API_KEY: process.env.HELIUS_API_KEY,
        SOLANA_RPC_URL: process.env.SOLANA_RPC_URL || 'https://api.mainnet-beta.solana.com',
        JWT_SECRET: process.env.JWT_SECRET || 'your-jwt-secret-key-here',
        CORS_ORIGIN: 'https://c4pad.fun,http://104.129.59.158:7171,http://localhost:7171',
        WEBSOCKET_CORS_ORIGIN: 'https://c4pad.fun',
        FRONTEND_URL: 'https://c4pad.fun'
      },
      env_development: {
        NODE_ENV: 'development',
        PORT: 7172,
        DATABASE_URL: 'postgresql://ignite:password@localhost:5432/ignite_db',
        CORS_ORIGIN: 'http://localhost:7171,http://127.0.0.1:7171'
      },
      log_file: './logs/backend-combined.log',
      out_file: './logs/backend-out.log',
      error_file: './logs/backend-error.log',
      log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
      merge_logs: true,
      max_memory_restart: '1G',
      min_uptime: '10s',
      max_restarts: 10,
      restart_delay: 4000,
      watch: false,
      ignore_watch: ['node_modules', 'logs', '.git'],
      kill_timeout: 5000
    },
    {
      name: 'frontend',
      script: 'npm',
      args: 'start',
      cwd: '/Users/zyu/leo/ignite-fun/frontend',
      instances: 1,
      exec_mode: 'fork',
      env: {
        NODE_ENV: 'production',
        PORT: 7171,
        NEXT_PUBLIC_API_URL: 'https://c4pad.fun/api',
        NEXT_PUBLIC_WS_URL: 'wss://c4pad.fun'
      },
      env_development: {
        NODE_ENV: 'development',
        PORT: 7171,
        NEXT_PUBLIC_API_URL: 'http://localhost:7172/api',
        NEXT_PUBLIC_WS_URL: 'ws://localhost:7172'
      },
      log_file: './logs/frontend-combined.log',
      out_file: './logs/frontend-out.log',
      error_file: './logs/frontend-error.log',
      log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
      merge_logs: true,
      max_memory_restart: '1G',
      min_uptime: '10s',
      max_restarts: 10,
      restart_delay: 4000,
      watch: false,
      ignore_watch: ['node_modules', '.next', 'logs', '.git'],
      kill_timeout: 5000
    }
  ],

  deploy: {
    production: {
      user: 'root',
      host: '104.129.59.158',
      ref: 'origin/main',
      repo: 'git@github.com:zyu/ignite.git',
      path: '/Users/zyu/leo/ignite-fun',
      'pre-deploy-local': '',
      'post-deploy': 'npm install && npm run build && pm2 reload ecosystem.config.js --env production',
      'pre-setup': ''
    }
  }
};
